#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = ''
__author__ = 'tyh'
__mtime__ = '18-10-10'
# code is far away from bugs with the god animal protecting ~
"""

from rest_framework import serializers

from areas.models import Area
from goods.models import SKU


class CartSerializer(serializers.Serializer):

	sku_id = serializers.IntegerField(label='商品信息', min_value=1)
	count = serializers.IntegerField(label='商品数量', min_value=1)
	selected = serializers.BooleanField(default=True, label='商品是否选中')

	def validate(self, attrs):
		try:
			sku_id = attrs.get('sku_id')
			SKU.objects.get(id=sku_id)
		except Exception as e:
			raise serializers.ValidationError('sku_id没有对应的用户')

		return attrs


class CartSKUSerializer(serializers.ModelSerializer):

	selected = serializers.BooleanField(default=True, label='商品是否选中')
	count = serializers.IntegerField(label='商品数量', min_value=1)

	class Meta:
		model = SKU
		fields = ('selected', 'count', 'default_image_url', 'id', 'name', 'price')


class CartSelectSerializer(serializers.Serializer):
	selected = serializers.BooleanField(label='商品是否选中')